import Vue from 'vue'
import { checkParams } from './check'

export const Wechart = {
    /**
	 * @description: 发送信息
	 * @param {String} account 消息账户
	 * @param {String} content 消息内容
     * @param {Array} userList 接收人
	 */
    async sendTextMsg(account=checkParams('消息账户'), content=checkParams('消息内容'), userList=checkParams('接收人')) {
        let params = {
            account,
            content,
            userList: typeof userList === 'object' ? userList : [userList],
        }
        let res = await Vue.prototype.$request({
            url: "/web/apps/gongqi.os.msgnotify/WorkWeChat/sendTextMessage",
            method: "post",
            data: params
          })
        if (res.errcode !== 0) {
            throw new Error(res.errmsg)
        }
    },

    /**
	 * @description: 发送模板
	 * @param {String} account 消息账户
	 * @param {String} modelId 模板名称
     * @param {Object} params 模板参数
     * @param {Array} userList 接收人
	 */
    async sendTemplateMsg(account=checkParams('消息账户'), modelId=checkParams('模板名称'), params=checkParams('模板参数'), userList=checkParams('接收人')) {
        let data = {
            account,
            modelId,
            params,
            userList: typeof userList === 'object' ? userList : [userList],
        }
        let res = await Vue.prototype.$request({
            url: "/web/apps/gongqi.os.msgnotify/WorkWeChat/sendModelMessage",
            method: "post",
            data
          })
        if (res.errcode !== 0) {
            throw new Error(res.errmsg)
        }
    },

    /**
	 * @description: 发送图片
	 * @param {String} account 消息账户
	 * @param {String} filePath 图片路径
     * @param {Array} userList 接收人
	 */
    async sendImageMsg(account=checkParams('消息账户'), filePath=checkParams('图片路径'), userList=checkParams('接收人')) {
        let params = {
            account,
            filePath,
            userList: typeof userList === 'object' ? userList : [userList],
        }
        let res = await Vue.prototype.$request({
            url: "/web/apps/gongqi.os.msgnotify/WorkWeChat/sendImageMessage",
            method: "post",
            data: params
          })
        if (res.errcode !== 0) {
            throw new Error(res.errmsg)
        }
    },

    /**
	 * @description: 发送文件
	 * @param {String} account 消息账户
	 * @param {String} filePath 文件路径
     * @param {Array} userList 接收人
	 */
    async sendFileMsg(account=checkParams('消息账户'), filePath=checkParams('文件路径'), userList=checkParams('接收人')) {
        let params = {
            account,
            filePath,
            userList: typeof userList === 'object' ? userList : [userList],
        }
        let res = await Vue.prototype.$request({
            url: "/web/apps/gongqi.os.msgnotify/WorkWeChat/sendFileMessage",
            method: "post",
            data: params
          })
        if (res.errcode !== 0) {
            throw new Error(res.errmsg)
        }
    }
}